package com.cx.base.day04;

/**
 * @author shkstart
 * @date 7/24/2019 - 9:07 AM
 */
public class 静态块 {

    static int a = 10;

    private static double d = initStaticVar();

    static {
        System.out.println(d + 5);
    }

    private static double initStaticVar() {
        System.out.println("当前d的值：" + d);
        return 1;
    }

    public static void main(String[] args) {
        静态块 j1 = new 静态块();

      /*  String str1 = "test";
        String str2 = new String("test");
        System.out.println(str1.equals(str2));*/
    }
}

class Sub extends 静态块 {

    static int a = 20;
    static final int b = 10;

    private static double d = initStaticVar();

    static {
        System.out.println(d + 5);
    }

    private static double initStaticVar() {
        System.out.println("当前d的值：" + d);
        return 1;
    }

    private void privateOverrideTest() {
        System.out.println("当前d的值：" + d);
    }

    private void privateReloadTest() {
        System.out.println("当前d的值：" + d);
    }

    public final static void staticExtendTest(){
        System.out.println("final 方法重载测试");
    }

    public static void main(String[] args) {
        System.out.println(Sub.a);

      /*  String str1 = "test";
        String str2 = new String("test");
        System.out.println(str1.equals(str2));*/
    }
}

class DeepSub extends Sub {

    static int a = 20;
//    static int b = 20;

    private static double d = initStaticVar();

    static {
        System.out.println(d + 5);
    }

    private static double initStaticVar() {
        System.out.println("当前d的值：" + d);
        return 1;
    }

    public void staticExtendTest(String str){
        System.out.println("final 方法重载测试");
    }

    {
        System.out.println("实例化初始块");
    }

    /**
     * @description
     * 执行顺序总结
     *
     * 类加载阶段：
     * 静态变量初始化
     * 静态初始化块（按代码顺序）
     *
     * 实例化阶段（每次new时）：
     * 实例变量初始化
     * 实例初始化块（按代码顺序）
     * 构造方法
     * @param args
     */
    public static void main(String[] args) {
        System.out.println(DeepSub.b);
        DeepSub deepSub = new DeepSub();
      /*  String str1 = "test";
        String str2 = new String("test");
        System.out.println(str1.equals(str2));*/
    }
}
